<template>
	<view>
		<view class="u-m-t-20 cbg-white">
			<view class="cflex-c u-p-25"  >
				<view class="cflex-r u-m-b-25" style="justify-content: space-between;align-items: center;" @tap="goZeRen()">
					<view>
						责任声明
					</view>
					<view class="u-m-r-10">
						<image style="width: 14rpx;height: 24rpx;" src="../../static/qieTu/arrow-right.png"></image>
					</view>
				</view>
				
				<view class="u-m-b-25" style="width: 100%;">
					<u-divider :use-slot="false" half-width="350"></u-divider>
				</view>
				
				<view class="cflex-r u-m-b-25" style="justify-content: space-between;align-items: center;"
				@tap="clearCache">
					<view>
						清除缓存
					</view>
					<view class="u-m-r-10 cflex-r">
						<view class="u-p-r-20" style="color: #aaaaaa;">
							{{cache}} MB
						</view>
						<view>
							<image style="width: 14rpx;height: 24rpx;" src="../../static/qieTu/arrow-right.png"></image>
						</view>
					</view>
				</view>
				
				<view class="u-m-b-25" style="width: 100%;">
					<u-divider :use-slot="false" half-width="350"></u-divider>
				</view>
				<view class="cflex-r u-m-b-25" style="justify-content: space-between;align-items: center;"
				>
					<view>
						版本
					</view>
					<view class="u-m-r-10 cflex-r">
						<view class="u-p-r-20" style="color: #aaaaaa;">
							v1.00
						</view>
						<view>
							<image style="width: 14rpx;height: 24rpx;" src="../../static/qieTu/arrow-right.png"></image>
						</view>
					</view>
				</view>
				
				
				
				
				
				
				
				
				
				<view class="u-m-b-25" style="width: 100%;">
					<u-divider :use-slot="false" half-width="350"></u-divider>
				</view>
				
				<view class="cflex-r u-m-b-25" style="justify-content: space-between;align-items: center;" 
				@tap="getNewVer()" v-show="AppShow">
					<view>
						检测新版本
					</view>
					<view class="u-m-r-10 cflex-r">
						<view class="u-p-r-20" style="color: #aaaaaa;">
							V1.0
						</view>
						<view>
							<image style="width: 14rpx;height: 24rpx;" src="../../static/qieTu/arrow-right.png"></image>
						</view>
					</view>
				</view>
				
				<view class="u-m-b-25" style="width: 100%;" v-show="AppShow">
					<u-divider :use-slot="false" half-width="350"></u-divider>
				</view>
				
				<!-- <view class="cflex-r" style="justify-content: space-between;align-items: center;"
				@tap="logout()">
					<view>
						注销账户
					</view>
					<view class="u-m-r-10">
						<image style="width: 14rpx;height: 24rpx;" src="../../static/qieTu/arrow-right.png"></image>
					</view>
				</view>	 -->
			</view>
		</view>
		
		<view class="u-m-t-60 u-m-20">
			<u-button :hair-line="false" :custom-style="customStyle" @click="save()">
				退出登录
			</u-button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					color: '#ffffff',
					backgroundColor: '#b8b8b8',
				},
				cache:0,
				AppShow:true
			}
		},
		onLoad() {
			this.getCache()
		},
		onShow() {
			// #ifdef APP-PLUS
			this.AppShow = true
			// #endif
			// #ifdef MP-WEIXIN
			this.AppShow = false
			// #endif
			// #ifdef H5
			this.AppShow = false
			// #endif
		},
		methods: {
			getCache(){//获得缓在storage里面的假缓存
				let myCache=uni.getStorageSync("cache")||{};//{}为默认的类型
				if(myCache.day===undefined){//第一次进入
					myCache.day=parseInt(new Date().getTime());//获得毫秒数
					myCache.cache=0;
				}
				else{//存在数据
					let nowDay=new Date().getTime();
					let timeDiff=((nowDay-myCache.day)/(1000*60*60*24)).toFixed(1);//相差天数
					if(timeDiff>=1){//是否同一天
						myCache.day=new Date().getTime();
						myCache.cache+=timeDiff*0.1;
						if(Math.floor(myCache.cache)>10){
							myCache.cache=8.34;
						}
					}
				}
				uni.setStorageSync('cache',myCache)
				// uni.removeStorageSync('cache')
				this.cache=myCache.cache.toFixed(2)
			},
			goZeRen(){
				uni.navigateTo({
					url:"./xieyi?url="+this.$store.state.url_5
				})
			},
			prevTime(){//上次时间
				
			},
			clearCache(){//清除缓存
				if(this.cache*100===0){
					uni.showToast({
						title:"暂无缓存",icon:'none'
					})
					return
				}
				uni.showLoading({
					title:'清除缓存中',
					success: (res) => {
						setTimeout(()=>{
							this.cache=0;
							this.cache=this.cache.toFixed(2);
							let myCache={day:parseInt(new Date().getTime()),cache:0};
							uni.setStorageSync("cache",myCache)
							uni.hideLoading()
						},1000)
					}
				})
			},
			//更新版本
			getNewVer(){
				uni.navigateTo({
					url:"./xieyi?url="+this.$store.state.url_6
				})
				// this.$request("worker/version/getVersion").then(res=>{
				// 	console.log(res)
				// });
			},
			logout(){//注销登录
				let isLogin = this.$store.state.isLogin;
				if(isLogin==false)
				{
					uni.showToast({
						icon:"none",
					    title: '您还没有登录',
					    duration: 2000
					});
					return
				}
				let that=this;
				console.log("注销");
				uni.showModal({
					title:"注销账户",
					content:' 确定注销吗？注销后将不能登录',
					success(res) {
						if(res.confirm){
							that.$request("worker/zhuXiao").then(res=>{
								console.log("注销",res)
								that.$store.commit("setLat","");
								that.$store.commit("setLng","");
								that.$store.commit("setAddress","");
								that.$store.commit("setIp","");
								that.$store.commit("setToken","");
								uni.reLaunch({
									url:'../login/login'
								})
							});
						}
					}
				})
			},
			save(){
				let isLogin = this.$store.state.isLogin;
				console.log(isLogin);
				if(isLogin==false){
					uni.showToast({
						icon:"none",
					    title: '您还没有登录',
					    duration: 2000
					});
				}else{
					uni.showModal({
						title:'提示',
						content:'确定退出登录？',
						success: (res) => {
							if(res.confirm){
								this.agree()
							}
						}
					})
				}
			},
			agree(){
				this.$store.commit("setLat","");
				this.$store.commit("setLng","");
				this.$store.commit("setAddress","");
				this.$store.commit("setIp","");
				this.$store.commit("setToken","");
				uni.reLaunch({
					url:'../../pages/login/login'
				})
			}
		}
	}
</script>

<style>



</style>
